package com.google.jguery.client.query;

import java.util.Map;
import java.util.Set;

import com.google.jguery.client.common.TermPostings;

public class Term extends SimpleQuery {

	TermPostings termPostings = null;
	
	public Term(String fieldName, String text, double boost) {
		super(fieldName, text, boost);
	}
	
	public Term(String fieldName, String text) {
		super(fieldName, text, 1.0);
	}
	
	public Term(String text) {
		super("body", text, 1.0);
	}
	
	public Term() {
	}
	
	public void setTermText(String text) {
		ft.setText(text);
	}
	
	public int estimateSize(Searcher searcher) {
		return searcher.getDocCount(ft);
	}
	
	//This could bring cross object confusion, think about it
	public void setTermPostings(Searcher searcher) {
		if (termPostings == null) {
			termPostings = searcher.getPostings(ft);
		}
	}
	
	public Set<Integer> getDocIds(Searcher searcher) {
		setTermPostings(searcher);
		if (termPostings == null) return null;
		return termPostings.getDocIds();
	}

	@Override
	public Map<Integer, Integer> getDocScoreMap(Searcher searcher) {
		// TODO Auto-generated method stub
		return null;
	}
	
	public String toString() {
		return "Field:" + field + "|Text:" + text + "|Boost:" + boost; 
	}
	
}